<%--
  Created by IntelliJ IDEA.
  User: Albert Lee
  Date: 2020/5/26
  Time: 17:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">

    <title>删除页面</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
</head>

<body>
<%
    request.setCharacterEncoding("UTF-8");
    String[] Id = request.getParameterValues("delete_id");
    System.out.println(Id);

    Connection conn = null;
    Statement stat = null;
    ResultSet rs = null;

    Class.forName("com.mysql.cj.jdbc.Driver");
    String url = "jdbc:mysql://localhost:3306/student";

    String user = "root";
    String password = "123456";
    conn = DriverManager.getConnection(url,user,password);

    int result = 0;
    int i = 1;
    stat = conn.createStatement();
//    stat.executeUpdate("delete from student where id = " + id + "");
    rs = stat.executeQuery("select * from stu");

//    out.print( rs.getInt("id") );


   if(conn != null) {
        stat = conn.createStatement();
        for(String id : Id ){
//            System.out.println( rs.getInt("id") );
            String sql = "delete from stu where id = " + id;
            System.out.println(sql);
            result = stat.executeUpdate(sql);
            if(result > 0){
                System.out.println("执行完毕");
            }
        }

        stat.close();
        conn.close();
        response.sendRedirect("showInfo.jsp");
    }else{
        out.print("数据库连接失败");
    }
%>
<br>
<br>
<center> <a href=addStuInfo.jsp>返回添加信息页面</a> <a href=showInfo.jsp>返回信息查询页面</a></center>
<%
    if(rs != null) {
        rs.close();
        rs = null;
    }
    if(stat != null) {
        stat.close();
        stat = null;
    }
    if(conn != null) {
        conn.close();
        conn = null;
    }
%>
</body>
</html>
